package com.sixteengroup.personnelms.service.portal;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sixteengroup.personnelms.bean.Menu;
import com.sixteengroup.personnelms.bean.User;
import com.sixteengroup.personnelms.bean.finance.TraProgram;
import com.sixteengroup.personnelms.dao.portal.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserService {

    @Autowired
    UserDao userDao;

    @Autowired
    UserService userService;


    public User login(User user) {
        return userDao.login(user);
    }

    public List<Menu> findMenuList(int id, int type) {
        List<Menu>  menuList =userDao.findMenuList(id, type);
        if (type!=0){
            List<Menu> menuLis = userDao.findMenuLis(id);
            for (Menu menu: menuLis) {
                menuList.add(menu);
            }
        }
        System.out.println(menuList);
        return menuList;
    }

    public void register(User user) {
        userDao.register(user);
    }

    public User isExist(String account) {
        User user1 = userDao.isExist(account);
        return user1;
    }

    public void updatePass(User user) {
        userDao.updatePass(user);
    }

    public PageInfo<User> getAccList(User user) {
        PageHelper.startPage(user.getCurrentPage(),user.getPagesize());
        List<User> userList = userDao.getAccList(user);
        PageInfo<User> page = new PageInfo<>(userList);
        return page;
    }

    public void updateType(User user) {
        if (user.getType() == 2){
            System.out.println(user.getType());
            user.setType(-2);
        }else {
            System.out.println(user.getType());
            user.setType(2);
        }
        userDao.updateType(user);
    }

}
